/*
 * @Author: linZeJian
 * @Date: 2022-04-25 10:02:37
 * @LastEditors: linZeJian
 * @LastEditTime: 2022-04-25 11:19:30
 * @Description: 
 */
import { fileURLToPath } from 'url'

import { defineConfig } from 'vite'
import { viteMockServe } from "vite-plugin-mock";
import legacy from '@vitejs/plugin-legacy'
import { createVuePlugin as vue2 } from 'vite-plugin-vue2'
// @ts-ignore
import vueTemplateBabelCompiler from 'vue-template-babel-compiler'
import scriptSetup from 'unplugin-vue2-script-setup/vite'

// https://vitejs.dev/config/
export default defineConfig({
  server: {
    host: '0.0.0.0',
    port: 3012,
    proxy: {
      // 代理
      '/api': {
        target: `https://...`,
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/idaas/, '')
      },
    },
  },
  plugins: [
    vue2({
      jsx: true,
      vueTemplateOptions: {
        compiler: vueTemplateBabelCompiler
      }
    }),
    viteMockServe({
      mockPath: "./src/mock", //mock文件地址
      localEnabled: true, // 是否开启本地的mock功能
      prodEnabled: false, // 生产打包开关
      // 这样可以控制关闭mock的时候不让mock打包到最终代码内
      injectCode: `
        import { setupProdMockServer } from './mockProdServer';
        setupProdMockServer();
      `,
      logger: false, //是否在控制台显示请求日志
      supportTs: false //打开后，可以读取 ts 文件模块。 请注意，打开后将无法监视.js 文件
    }),
    scriptSetup(),
    legacy({
      targets: ['ie >= 11'],
      additionalLegacyPolyfills: ['regenerator-runtime/runtime']
    })
  ],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    }
  }
})
